<?php

class hdms_groupModel extends FoundryModel
{

	protected $beforeSave		= 'preSave';

	protected $afterSave		= 'postSave';

	protected $afterFind		= 'postFind';
	
	/**
	 * init()
	 *
	 * init() is called in place of the __construct() method used by the
	 * FoundryModel super class
	 * This function will be called immediately after the __construct method
	 *
	 */ 
	public function init()
	{
	
	
	}
	
	public function preSave()
	{
		if( $this->role ) {
			if( !in_array( 'adminMain', $this->role ) ) {
				$tmp = $this->role;
				$tmp[] = 'adminMain';
				
				$this->role = $tmp;
			}
			
			$this->role = serialize( $this->role );
		}
	}

	public function postSave()
	{
		if( $this->role ) {
			$this->role = unserialize( $this->role );
		}
	}
	
	public function postFind( $data )
	{
		for( $i=0; $i<count( $data ); $i++ ) {
		
			if( $data[$i]['role'] !== '1' ) {
				$data[$i]['role'] = unserialize( $data[$i]['role'] );
			}
		
		}
	}
}

?>